package pl.edu.amu.wmi.kino.visualjavafx.model.animation.transformations;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import pl.edu.amu.wmi.kino.visualjavafx.model.animation.interpolators.Interpolation;
import pl.edu.amu.wmi.kino.visualjavafx.model.objects.VisualObject;

// <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
// #[regen=yes,id=DCE.25FB0DF9-2C60-289F-127A-2A651CA45B9C]
// </editor-fold> 
public class ChangeOpacity implements Transformation ,java.io.Serializable{

    // Code block for changeListeners support start
    protected PropertyChangeSupport propertySupport= new PropertyChangeSupport(this);
    public void addPropertyChangeListener(PropertyChangeListener listener) {
        propertySupport.addPropertyChangeListener(listener);
    }
    public void removePropertyChangeListener(PropertyChangeListener listener) {
        propertySupport.removePropertyChangeListener(listener);
    }
    // Code block for changeListeners support end

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.3412F7F9-E31B-F2C7-7F91-E0F7CDC841D2]
    // </editor-fold> 
    public ChangeOpacity () {
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.DEE2066E-B278-ACE5-69C1-AFC9217058E4]
    // </editor-fold> 
    @Override
    public Interpolation getInterpolation () {
        return this.myInterpolation[0];
    }

    @Override
    public Interpolation[] getInterpolations() {
        return this.myInterpolation;
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.F6197DB9-A231-FDEA-3BD8-497C62C2A34B]
    // </editor-fold> 
    @Override
    public void setInterpolation (Interpolation i) {
        Interpolation oldVal = this.myInterpolation[0];
        this.myInterpolation[0]=i;
        propertySupport.firePropertyChange( "Inerpolation" , oldVal, i);
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.B3223571-E922-864A-9C02-35FBAA7D8BA1]
    // </editor-fold> 
    @Override
    public VisualObject transform (double howMuch, VisualObject transformable,VisualObject orginalTransformedObject) {
        if((transformable instanceof Opacitable)==false){
            return transformable;
        }

        Opacitable res = (Opacitable)transformable;
        double opacity = this.getInterpolation().getValue(howMuch, res.getOpacity(), this.destinedOpacity);
        res.setOpacity(opacity);

        return (VisualObject)res;
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.2B38522B-CDD4-58B8-2590-F933A32A4D4A]
    // </editor-fold> 
    public double getDestinedOpacity () {
        return this.destinedOpacity;
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.77DC4665-3D3B-0C3F-B9FD-F6988C56325A]
    // </editor-fold> 
    public void setDestinedOpacity (double val) {
        double oldVal = this.destinedOpacity;
        this.destinedOpacity=val;
        propertySupport.firePropertyChange( "destinedOpacity" , oldVal, val);
    }

    private Interpolation[] myInterpolation=new Interpolation[1];
    private double destinedOpacity=1.0d;



}

